package edu.whu.webgis.controller;

import edu.whu.webgis.entity.User;
import edu.whu.webgis.entity.VUser;
import edu.whu.webgis.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserServiceImpl userService;


    @GetMapping("/get")
    public ResponseEntity<User> getUSerById(@RequestParam String id){
        User user = userService.getUser(id);
        if (user != null){
            return ResponseEntity.ok(user);
        }
        else{
            return ResponseEntity.noContent().build();
        }
    }
    @GetMapping("/getAllBaseInfo")
    public ResponseEntity<List<Map<String,String>>> getBaseInfo(){
        List<Map<String,String>> map = userService.getAllBaseInfo();
        if (map != null){
            return ResponseEntity.ok(map);
        }
        else{
            return ResponseEntity.noContent().build();
        }
    }

    @GetMapping("/avatar")
    public ResponseEntity<String> getAvatar(@RequestParam String id){
        return ResponseEntity.ok(userService.getAvatar(id));
    }

    @PostMapping("/update")
    public ResponseEntity<String> updateBaseInfo(@RequestBody User user){
        userService.updateBaseInfo(user);
        return ResponseEntity.ok("更新成功");
    }

    @GetMapping("/detail")
    public ResponseEntity<VUser> getUserDetail(@RequestParam String id){
        return ResponseEntity.ok(userService.getUserDetail(id));
    }

}
